package com.zyx.javademo.stream;

import java.util.Arrays;
import java.util.stream.Stream;

/**
 * @author Yaxi.Zhang
 * @since 2021/12/3 13:10
 * desc: Stream与Array的相互转换
 */
public class StreamArrayDemo {
    public static void main(String[] args) {
        // Stream转Array
        String[] strs = Stream.of("aa", "bb", "cc").toArray(String[]::new);
        System.out.println(Arrays.toString(strs));

        // Array转Stream
        Stream<String> stream = Arrays.stream(strs);
        stream.forEach(System.out::println);

        // Array转Stream
        Character[] chars = {'a', 'b', 'c', 'd'};
        String s = Arrays.stream(chars).map(Object::toString).reduce((acc, e) -> acc + e).get();
        System.out.println(s);
    }
}
